#pragma once
#ifndef NODESOCKET_H
#define NODESOCKET_H


#include<QGraphicsItem>
#include<QColor>
#include<QtGui>
#include<QDebug>
#include<QGraphicsSceneMouseEvent>

#include"types.h"

class NodeSocket:public QGraphicsItem
{
public:
    NodeSocket(QGraphicsItem *parent = nullptr);
    NodeSocket(const NodeSocket &socket,QGraphicsItem *parent = nullptr);
    ~NodeSocket();
    void operator=(const NodeSocket &socket);
    void setIndex(int index);
    void setType(enum SOCKET_TYPE type);
    void setPosition();
    int type() const override {return Type_NodeSocket;}

    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
    QRectF boundingRect()const override;
    bool contains(const QPointF &point) const override;
    void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;


    enum SOCKET_TYPE socket_type;  // input or output
    int index;      // socket index
    int node_index;     // 该socket属于的node的index

//    int node_index=-1;  // 连接上该socket的节点
//    int out_socket_index =-1;   // 连接上该socket的节点的socket

    bool isSocketSelected = false;
    bool isConnected = false;    // only input socket need



private:
    // paint 相关
    float radius = 6.0;
    std::shared_ptr<QColor> color_basic;// socket 颜色  basic:number, image:image
    std::shared_ptr<QColor> color_outline;
    std::shared_ptr<QPen> pen;
    std::shared_ptr<QBrush> brush;
};
#endif // NODESOCKET_H
